const http = require('http');
const fs = require('fs');
const path = require('path');
const url = require('url');

const server = http.createServer((req, res) => {
    const parsedUrl = url.parse(req.url);
    let pathname = parsedUrl.pathname;

    if (pathname === '/') {
        pathname = '/employee-indicator-table.html';
    }

    const filePath = path.join(__dirname, pathname);

    fs.readFile(filePath, (err, data) => {
        if (err) {
            res.writeHead(404);
            res.end('File not found');
            return;
        }

        const ext = path.extname(filePath);
        let contentType = 'text/html';

        if (ext === '.css') {
            contentType = 'text/css';
        } else if (ext === '.js') {
            contentType = 'application/javascript';
        }

        res.writeHead(200, { 'Content-Type': contentType });
        res.end(data);
    });
});

const PORT = 3000;
server.listen(PORT, () => {
    console.log(`Server running at http://localhost:${PORT}`);
    console.log('Available pages:');
    console.log('- Employee Indicator Table: http://localhost:3000/employee-indicator-table.html');
    console.log('- Employee Indicator Form: http://localhost:3000/employee-indicator-form.html');
    console.log('- Department KPI Config: http://localhost:3000/department-kpi-config.html');
    console.log('- KPI Indicator Management: http://localhost:3000/kpi-indicator-management.html');
    console.log('- User List: http://localhost:3000/user-list.html');
    console.log('- AI Knowledge QA: http://localhost:3000/ai-knowledge-qa.html');
});